package com.macro.mall.es.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.common.dto.IndexDto;
import com.macro.mall.es.service.EsIndexService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Es索引示例(MySQL的数据库)
 */
@Controller
@RequestMapping("/index")
@Tag(name = "EsDocController", description = "Es索引示例接口")
public class EsIndexController {
    @Autowired
    private EsIndexService esIndexService;
    @Autowired
    private RestHighLevelClient restHighLevelClient;
    private static final Logger LOGGER = LoggerFactory.getLogger(EsIndexService.class);

    /**
     * 创建索引
     * @param indexDto
     * @return
     */
    @PostMapping("/createIndex")
    public CommonResult createIndex(@RequestBody IndexDto indexDto){
        esIndexService.createIndex(indexDto);
        return CommonResult.success("创建成功");
    }

    /**
     * 修改索引
     * @param indexDto
     * @return
     */
    @PutMapping("/updateIndex")
    public CommonResult updateIndex(@RequestBody IndexDto indexDto) {
        esIndexService.updateIndex(indexDto);
        return CommonResult.success("修改成功");

    }
        /**
     * 删除索引
     * @param indexName
     * @return
     */
    @DeleteMapping("/deleteIndex/{indexName}")
    public CommonResult deleteIndex(@PathVariable String indexName){
        esIndexService.deleteIndex(indexName);
        return CommonResult.success("删除成功");
    }
}

